<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>

<%
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + request.getContextPath() + "/";
    request.setAttribute("basePath", basePath);
%>
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>后台管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="${basePath}css/font.css">
    <link rel="stylesheet" href="${basePath}css/xadmin.css">
    <script type="text/javascript" src="${basePath}js/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" src="${basePath}lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${basePath}js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" href="${basePath}css/xcConfirm.css" type="text/css">
    <script src="${basePath}js/xcConfirm.js"></script>
    <script src="${basePath}lib/My97DatePicker/WdatePicker.js"></script>
</head>
<script>
    $(function () {
        try {
            var index = parent.layer.getFrameIndex(window.name);
            window.parent.location.reload();
            parent.layer.close(index);
        } catch (e) {

        }
    });
</script>
<body>
<div class="x-body connect_wrap">
    <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so layui-form-pane" method="get">
            <input class="layui-input" placeholder="优惠券名称" name="title" value="${page.conMap.title}">
            <div class="layui-input-inline">
                <select name="ftype">
                    <option value="">优惠券类型</option>
                    <option value="-1" ${page.conMap.ftype == "-1" ? 'selected="selected"' : '' }>全部</option>
                    <option value="0" ${page.conMap.ftype == 0 ? 'selected="selected"' : '' }>抵扣券</option>
                    <option value="1" ${page.conMap.ftype >= 1 ? 'selected="selected"' : '' }>满减</option>
                </select>
            </div>
            <div class="layui-input-inline">
                <select name="limits">
                    <option value="">适用范围</option>
                    <option value="1" ${page.conMap.limits == 1 ? 'selected="selected"' : '' }>全场</option>
                    <option value="2" ${page.conMap.limits == 2 ? 'selected="selected"' : '' }>课程</option>
                    <option value="3" ${page.conMap.limits == 3 ? 'selected="selected"' : '' }>章节</option>
                    <option value="4" ${page.conMap.limits == 4 ? 'selected="selected"' : '' }>年卡</option>
                </select>
            </div>
            <input class="layui-input" placeholder="用户名" name="userName" value="${page.conMap.userName}">
            <input class="layui-input" placeholder="手机号" name="telephone" value="${page.conMap.telephone}">
            <div class="layui-input-inline">
                <select name="coupons_source">
                    <option value="">来源</option>
                    <option value="1" ${page.conMap.coupons_source == 1 ? 'selected="selected"' : '' }>系统发放</option>
                    <option value="2" ${page.conMap.coupons_source == 2 ? 'selected="selected"' : '' }>活动领取</option>
                    <option value="3" ${page.conMap.coupons_source == 3 ? 'selected="selected"' : '' }>邀请领取</option>
                    <option value="4" ${page.conMap.coupons_source == 4 ? 'selected="selected"' : '' }>退货返回</option>
                </select>
            </div>
            <input class="layui-input" placeholder="使用时间-开始" name="stime" value="${page.conMap.stime}"
                   onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})">
            <input class="layui-input" placeholder="使用时间-结束" name="etime" value="${page.conMap.etime}"
                   onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})">
            <input class="layui-input" placeholder="获取优惠券时间-开始" name="receivestart" value="${page.conMap.receivestart}"
                   onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})">
            <input class="layui-input" placeholder="获取优惠券时间-结束" name="receivend" value="${page.conMap.receivend}"
                   onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})">
            <div class="layui-input-inline">
                <select name="status">
                    <option value="">是否使用</option>
                    <option value="1" ${page.conMap.status == 1 ? 'selected="selected"' : '' }>已使用</option>
                    <option value="2" ${page.conMap.status == 2 ? 'selected="selected"' : '' }>未使用</option>
                </select>
            </div>
            <button class="layui-btn" lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
        </form>
    </div>
    <xblock>
        <button class="layui-btn" onclick="del()">
            <i class="layui-icon"></i>删除
        </button>
        <span class="x-right" style="line-height:40px">共有数据：${page.totalCount} 条</span>
    </xblock>
    <table class="layui-table">
        <thead>
        <tr>
            <td><input id="allCkb" type="checkbox"/></td>
            <td>序号</td>
            <td>用户名</td>
            <td>手机号</td>
            <td>优惠券标题</td>
            <td>面值</td>
            <td>优惠券类型</td>
            <td>适用范围</td>
            <td>是否使用</td>
            <td>使用时间</td>
            <td>来源</td>
            <td>获取时间</td>
            <td>操作</td>
        </tr>
        </thead>
        <tbody>
        <c:if test="${not empty page.results}">
            <c:forEach items="${page.results}" var="result" varStatus="vs">
                <tr>
                    <td>
                        <c:if test="${result.status eq 1 }">已使用,不能删除</c:if>
                        <c:if test="${result.status eq 2 }"><input type='checkbox' name='ckb'
                                                                   value="${result.id }"/></c:if>
                    </td>
                    <td>${(page.actulPageNo - 1) * 15 + vs.count}</td>
                    <td>${result.userName} </td>
                    <td>${result.telephone}</td>
                    <td>${result.title}</td>
                    <td>${result.cost}</td>
                    <td>
                        <c:choose>
                            <c:when test="${result.ftype eq '0'}">抵扣券</c:when>
                            <c:otherwise>满${result.ftype}可用</c:otherwise>
                        </c:choose>
                    </td>
                    <td>
                        <c:if test="${result.limits eq '1'}">全场</c:if>
                        <c:if test="${result.limits eq '2'}">课程</c:if>
                        <c:if test="${result.limits eq '3'}">章节</c:if>
                        <c:if test="${result.limits eq '4'}">年卡</c:if>
                    </td>
                    <td>
                        <c:if test="${result.status eq 1 }">已使用</c:if>
                        <c:if test="${result.status eq 2 }">未使用</c:if>
                    </td>
                    <td>${result.spend_time} </td>
                    <td>
                        <c:if test="${result.coupons_source eq 1 }">系统发放</c:if>
                        <c:if test="${result.coupons_source eq 2 }">活动领取</c:if>
                        <c:if test="${result.coupons_source eq 3 }">邀请领取</c:if>
                        <c:if test="${result.coupons_source eq 4 }">退货返回</c:if>
                    </td>
                    <td>${result.receive_time}</td>
                    <td>
                        <c:if test="${result.status eq 1 }">已使用,不能删除</c:if>
                        <c:if test="${result.status eq 2 }">
                            <button class="layui-btn-danger layui-btn layui-btn-xs" onclick="_del('${result.id}')"
                                    href="javascript:;"><i class="layui-icon">&#xe640;</i>删除
                            </button>
                        </c:if>
                    </td>
                </tr>
            </c:forEach>
        </c:if>
        </tbody>
    </table>
    <div class="page">
        <c:if test="${page.totalPageNo > 1 }">
            <div>
                <a class="num" href='${basePath}${page.url}?pageNo=1${page.params}'>首页</a>
                <c:if test="${page.actulPageNo > 1 }">
                    <a class="prev"
                       href='${basePath}${page.url}?pageNo=${page.actulPageNo - 1}${page.params}'>上一页</a>
                </c:if>
                <c:forEach var="pno" items="${page.showNums }">
                    <c:choose>
                        <c:when test="${pno == page.actulPageNo}">
                            <span class="current"> ${pno }</span>
                        </c:when>
                        <c:otherwise>
                            <c:if test="${not empty pno}">
                                <a class="num"
                                   href='${basePath}${page.url}?pageNo=${pno  }${page.params}'>${pno }</a>
                            </c:if>
                        </c:otherwise>
                    </c:choose>
                </c:forEach>
                <c:if test="${page.actulPageNo  < page.totalPageNo }">
                    <a class="next" href='${basePath}${page.url}?pageNo=${page.actulPageNo + 1}${page.params}'>下一页</a>
                </c:if>
                <a class="num" href='${basePath}${page.url}?pageNo=${page.totalPageNo }${page.params}'>尾页</a>
            </div>
        </c:if>
    </div>
</div>
<script>
    layui.use(['form'], function () {
        form = layui.form;

    });

    function _del(id) {
        layer.confirm('确认要删除吗？', function () {
            var url = "${basePath}MemberCoupons/deleteMemberCoupons/" + id;
            location.href = url;
        });
    }

    function del() {
        if (confirm("确认删除吗？删除之后，不可恢复") == true) {
            var ids = [];
            $("input[name=ckb]:checked").each(function () {
                ids.push($(this).val());
            });
            if (ids.length <= 0) {
                var txt = "请选择要删除的优惠券！";
                window.wxc.xcConfirm(txt, window.wxc.xcConfirm.typeEnum.error);
                return false;
            }
            ;
            $.ajax({
                type: "POST",
                async: true,
                data: {"ids": ids},
                dataType: 'json',
                url: "${basePath}MemberCoupons/batcDelete",
                success: function (data) {
                    var txt = "删除成功！";
                    var option = {
                        title: "删除成功",
                        onOk: function () {
                            window.location.href = '${basePath}MemberCoupons/queryMemberCoupon';
                        }
                    }
                    window.wxc.xcConfirm(txt, "custom", option);
                }
            });
        }
    };

    $("#allCkb").click(function () {
        if (this.checked) {
            $(".connect_wrap :checkbox").prop("checked", true);
        } else {
            $(".connect_wrap :checkbox").prop("checked", false);
        }
    });
</script>
</body>

</html>